// MainFrm.cpp : implementation of the CMainFrame class
//

#include "stdafx.h"
#include "PerSim.h"
#include "PerSimDoc.h"
#include "MainFrm.h"
#include "PerSimView.h"
#include "LeftWindow.h"
#include "MainWindow.h"
#include "SettingThreshold.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
using namespace ccgis ;
/////////////////////////////////////////////////////////////////////////////
// CMainFrame
extern CTestApp theApp;

IMPLEMENT_DYNAMIC(CMainFrame, CBCGPMDIFrameWnd)

BEGIN_MESSAGE_MAP(CMainFrame, CBCGPMDIFrameWnd)
	//{{AFX_MSG_MAP(CMainFrame)
	ON_WM_CREATE()
	ON_COMMAND(IDC_ROTATE, OnRotate)
	ON_COMMAND(IDC_CENTER, OnCenter)
	ON_COMMAND(IDC_ARROW_ICON, OnArrowIcon)
	ON_COMMAND(IDC_PAN, OnPan)
	ON_COMMAND(IDC_PARA_PAGE, OnParaPage)
	ON_UPDATE_COMMAND_UI(IDC_PARA_PAGE, OnUpdateParaPage)
	ON_COMMAND(IDC_KEY_HOT, OnKeyHot)
	ON_UPDATE_COMMAND_UI(IDC_KEY_HOT, OnUpdateKeyHot)
	ON_MESSAGE(INFO_CHANGED,SetInfo)
	ON_COMMAND(IDD_SetThread, OnSetThread)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

static UINT indicators[] =
{
	ID_SEPARATOR,           // status line indicator
	//ID_INDICATOR_CAPS,
//	ID_INDICATOR_NUM,
	//ID_INDICATOR_SCRL,
	0,
	0,
	0,
};

/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction

CMainFrame::CMainFrame()
{
	// TODO: add member initialization code here
	m_nCurTool = CCTOOL_DEFAULT ;
	m_bShowHotKey = FALSE ;
}

CMainFrame::~CMainFrame()
{
}

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CBCGPMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	
	if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
		| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
		!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
	{
		TRACE0("Failed to create toolbar\n");
		return -1;      // fail to create
	}

	if (!m_wndStatusBar.Create(this) ||
		!m_wndStatusBar.SetIndicators(indicators,
		  sizeof(indicators)/sizeof(UINT)))
	{
		TRACE0("Failed to create status bar\n");
		return -1;      // fail to create
	}

	// TODO: Delete these three lines if you don't want the toolbar to
	//  be dockable
	m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
	EnableDocking(CBRS_ALIGN_ANY);
	DockControlBar(&m_wndToolBar);
	

   if (!m_wndOutput.Create ("", this, CRect (0, 0, 150, 116),
		FALSE /* Has gripper */, ID_VIEW_OUTPUT,
		WS_CHILD | WS_VISIBLE | CBRS_BOTTOM))
	{
		TRACE0("Failed to create output bar\n");
		return -1;      // fail to create
	}
	
	m_wndOutput.EnableDocking(CBRS_ALIGN_BOTTOM);
	EnableDocking(CBRS_ALIGN_ANY);
	
	DockControlBar(&m_wndOutput, AFX_IDW_DOCKBAR_BOTTOM);


	return 0;
}

BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
	if( !CBCGPMDIFrameWnd::PreCreateWindow(cs) )
		return FALSE;
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return TRUE;
}

/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics

#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
	CBCGPMDIFrameWnd::AssertValid();
}

void CMainFrame::Dump(CDumpContext& dc) const
{
	CBCGPMDIFrameWnd::Dump(dc);
}

#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers


void CMainFrame::OnRotate() 
{
	m_nCurTool = CCTOOL_MODEL_ROATE ;
}



void CMainFrame::OnCenter() 
{
	// TODO: Add your command handler code here
}

void CMainFrame::OnArrowIcon() 
{
	// TODO: Add your command handler code here
	m_nCurTool = CCTOOL_DEFAULT ;
	//Invalidate(FALSE) ;
}



void CMainFrame::OnPan() 
{
	// TODO: Add your command handler code here
//	m_nCurTool = CCTOOL_MODEL_PAN ;
}

void CMainFrame::OnParaPage() 
{
	// TODO: Add your command handler code here
	m_wndOutput.ShowControlBar (!m_wndOutput.IsVisible (), FALSE, FALSE);
	RecalcLayout();	
	Invalidate(FALSE) ;
}

void CMainFrame::OnUpdateParaPage(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetCheck((m_wndOutput.GetStyle () & WS_VISIBLE) ? TRUE : FALSE);
}

void CMainFrame::OnKeyHot() 
{
	// TODO: Add your command handler code here
	CTestDoc *pDoc = (CTestDoc*)MDIGetActive()->GetActiveView()->GetDocument();
	if(!pDoc->m_bLoadSucess)
		return ;
	m_bShowHotKey =! m_bShowHotKey ;
	pDoc->m_pMainView->m_pSence.ShowHotkeyWnd(m_bShowHotKey) ;
	pDoc->m_pLeftView->m_RightSence.ShowHotkeyWnd(m_bShowHotKey) ;

	Invalidate(FALSE) ;
}

void CMainFrame::OnUpdateKeyHot(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	CTestDoc *pDoc = (CTestDoc*)MDIGetActive()->GetActiveView()->GetDocument();
	pCmdUI->Enable(pDoc->m_bLoadSucess);
	pCmdUI->SetCheck(m_bShowHotKey) ;
}

LRESULT CMainFrame::SetInfo(WPARAM wParam, LPARAM lParam)
{
	int nPanIndex = (int)wParam;
	m_wndStatusBar.SetPaneText(nPanIndex, (LPCSTR)lParam, TRUE);
	return 0 ;
} 

void CMainFrame::OnSetThread() 
{
	// TODO: Add your command handler code here
//	CTestDoc *pDoc = (CTestDoc*)MDIGetActive()->GetActiveView()->GetDocument();
}
